package com.gec.it.web;


import com.gec.it.entity.Depts;
import com.gec.it.entity.Doctors;
import com.gec.it.service.DeptsService;
import com.gec.it.service.impl.DeptsServiceImpl;
import oracle.jdbc.proxy.annotation.Post;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wf
 * @since 2022-01-05
 */
@Controller
public class DeptsController {
    @Autowired
    private DeptsService service = null;

    @GetMapping("/dept_list")
    public String dept_list(Model m){
        List<Depts> depts = service.list2();
        m.addAttribute("list",depts);
        return "dept_list";
    }

    @GetMapping("/dept_add")
    public String dept_add(){
        return "dept_add";
    }

    @PostMapping("/dept_add")
    public String dept_add(Depts depts){
        System.out.println(depts);
        service.save(depts);
        return "redirect:dept_list";
    }

    @GetMapping("/dept_edit")
    public String dept_edit(int id,Model m){
        Depts byId = service.getById2(id);
        m.addAttribute("list",byId);
        return "dept_edit";
    }

    @PostMapping("/dept_edit")
    public String dept_edit(int id,Depts depts){
        depts.setDeptId(id);
        service.updateById(depts);
        return "redirect:dept_list";
    }

    @GetMapping("/dept_del")
    public String dept_del(int id){
        service.removeById(id);
        return "redirect:dept_list";
    }
}
